import * as TYPE from "../action-type";
import * as _ from "lodash";
import { sStorage } from "@/utils/storage";

const activeTag = sStorage.get("activeTag");
const tags = sStorage.get("tags");

let initialValue = {
  tags: tags || [], //显示所有标签
  activeTag: activeTag || "", //当前激活标签
};

const TagsReducer = (state = initialValue, action) => {
  state = _.cloneDeep(state);
  switch (action.type) {
    case TYPE.TAGS_SETTAGS:
      state.tags = action.tags;
      break;
    case TYPE.TAGS_SETACTIVETAG:
      state.activeTag = action.activeTag;
      break;
    case TYPE.TAGS_ADDTAGS:
      break;
    case TYPE.TAGS_RESETTAGS:
      break;
    default:
      initialValue = {
        tags: tags || [], //显示所有标签
        activeTag: activeTag || "", //当前激活标签
      };
  }
  return state;
};

export default TagsReducer;
